********************************************************************************
*                                                                              *
*                       Mike Cowburn & Marius Sältzer                          *
*                                                                              *
*              Partisan Communication in Two-Stage Elections:                  *
*       The Effect of Primaries on Intra-Campaign Positional Shifts            *
*                      in Congressional Elections                              *
*                                                                              *
*                  Political Science Research & Methods                        *
*                                                                              *
*    Replication Code for Dickey-Fuller Tests Only (all other analyses in R)   *
********************************************************************************

cd "XXXXX" // set to wherever files are stored locally
use "fuller", clear
tsset panel ttp

***Main Analysis***

// Dickey Fuller on DVs
dfuller position_20 if panel == 0, trend lags(1) // Republican losers
dfuller position_20 if panel == 1, trend lags(1) // Republican winners
dfuller position_20 if panel == 10, trend lags(1) // Democratic losers
dfuller position_20 if panel == 11, trend lags(1) // Democratic winners

// Dickey-Fuller on Residuals

itsa position_20 if democratic ==1, trperiod(0) treatid(10) posttrend
predict u_dem, residuals

drop _position_20 _t _z _z_t _x0 _x_t0 _z_x0 _z_x_t0 _m__position_20_pred
itsa position_20 if democratic ==0, trperiod(0) treatid(0) posttrend
predict u_rep, residuals

dfuller u_rep if panel == 0, trend lags(1) // Republican losers
dfuller u_rep if panel == 1, trend lags(1) // Republican winners
dfuller u_dem if panel == 10, trend lags(1) // Democratic losers
dfuller u_dem if panel == 11, trend lags(1) // Democratic winners

***Policy Only****

// Dickey Fuller on DVs
dfuller position_policy if panel == 0, trend lags(1) // Republican losers
dfuller position_policy if panel == 1, trend lags(1) // Republican winners
dfuller position_policy if panel == 10, trend lags(1) // Democratic losers
dfuller position_policy if panel == 11, trend lags(1) // Democratic winners

// Dickey-Fuller on Residuals

drop _position _t _z _z_t _x0 _x_t0 _z_x0 _z_x_t0 _m__position_20_pred
itsa position_policy if democratic ==1, trperiod(0) treatid(10) posttrend
predict u_dem_policy, residuals

drop _position_policy _t _z _z_t _x0 _x_t0 _z_x0 _z_x_t0 _m__position_policy
itsa position_policy if democratic ==0, trperiod(0) treatid(0) posttrend
predict u_rep_policy, residuals

dfuller u_rep_policy if panel == 0, trend lags(1) // Republican losers
dfuller u_rep_policy if panel == 1, trend lags(1) // Republican winners
dfuller u_dem_policy if panel == 10, trend lags(1) // Democratic losers
dfuller u_dem_policy if panel == 11, trend lags(1) // Democratic winners